package com.navinfo.collect.library.map.flutter.maphandler

import android.content.Context
import com.navinfo.collect.library.map.NIMapView
import com.navinfo.collect.library.map.flutter.FlutterMapConversion
import com.navinfo.collect.library.map.maphandler.LineHandler
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import org.oscim.core.GeoPoint

/**
 * 线数据操作控制
 */
class FlutterLineHandler(context: Context, mapView: NIMapView) :
    LineHandler(context, mapView) {

    /**
     * 给线数据增加一个点，如果是经纬度就用经纬度，如果是屏幕坐标就转换成经纬度
     */
    fun addDrawLinePoint(call: MethodCall, result: MethodChannel.Result) {
        val list = addDrawLinePoint(
            GeoPoint(
                mMapView.vtmMap.mapPosition.latitude,
                mMapView.vtmMap.mapPosition.longitude
            )
        )
        result.success(FlutterMapConversion.lineToJson(list));
//        if (call.hasArgument("xPixel") && call.hasArgument("yPixel")) {
//            val x = call.argument<Double>("xPixel")
//            val y = call.argument<Double>("yPixel")
//            val geoPoint =
//                mMapView.vtmMap.viewport().fromScreenPoint(x!!.toFloat(), y!!.toFloat())
//            val list = addDrawLinePoint(geoPoint)
//            result.success(FlutterMapConversion.lineToJson(list));
//        } else if (call.hasArgument("longitude") && call.hasArgument("latitude")) {
//            val lon = call.argument<Double>("longitude")
//            val lat = call.argument<Double>("latitude")
//            val list = addDrawLinePoint(GeoPoint(lat!!, lon!!))
//            result.success(FlutterMapConversion.lineToJson(list));
//        } else {
//            result.error("-1", "marker添加错误", "")
//        }
    }

    fun clean(call: MethodCall, result: MethodChannel.Result) {
        clean()
        result.success(true)
    }
}